package demo9;

import demo6.Student;

import java.util.ArrayList;

/*
自定义四个学生对象，添加到集合，并且遍历
 */
public class ArrayListTest2 {
    public static void main(String[] args) {
        ArrayList<Student> list = new ArrayList<>();
        //创建学生对象
        Student stu1 = new Student("李树强",19);
        Student stu2 = new Student("李罗正",20);
        Student stu3 = new Student("赵自强",22);
        Student stu4 = new Student("王涛",21);
        //把对象元素当中去
        list.add(stu1);
        list.add(stu2);
        list.add(stu3);
        list.add(stu4);

        //遍历输出
        for (int i = 0; i < list.size(); i++) {
            Student s = list.get(i);
            System.out.println(s.getName()+"   "+s.getAge());
        }

    }
}
